home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / v12n04.zip / FINDFI.BAS < prev    next >
BASIC Source File  |  1992-06-15  |  2KB  |  94 lines

  1. DEFINT A-Z
  2.  
  3. '$INCLUDE: 'QB.BI'
  4.  
  5. DECLARE FUNCTION FindFirst% (FileSpec$, Attribute%)
  6. DECLARE FUNCTION FindNext% ()
  7. DECLARE FUNCTION Trim$ (Work$)
  8.  
  9. TYPE DTAType
  10.   Reserved  AS STRING * 21
  11.   Attribute AS STRING * 1
  12.   DateTime  AS LONG
  13.   FileSize  AS LONG
  14.   FileName  AS STRING * 13
  15. END TYPE
  16.  
  17. DIM SHARED DTA AS DTAType
  18. DIM SHARED Regs AS RegType
  19.  
  20. DirFlag = 0                     'set to -1 to get directories
  21. Attribute = 7                   'match all file attributes
  22. IF DirFlag THEN Attribute = 19
  23.  
  24. DO
  25.    CLS
  26.    LOCATE 2, 1, 1
  27.    LINE INPUT "Enter a file specification: "; FSpec$
  28.    PRINT
  29.    NumFound = 0
  30.  
  31.    IF FindFirst%(FSpec$, Attribute) THEN
  32.       DO
  33.     IF DirFlag THEN               'for directories
  34.       IF ASC(DTA.Attribute) AND 16 THEN
  35.         PRINT Trim$(DTA.FileName)
  36.         NumFound = NumFound + 1
  37.       END IF
  38.     ELSE                          'for regular files
  39.       PRINT Trim$(DTA.FileName); TAB(17);
  40.       PRINT USING "########"; DTA.FileSize
  41.       NumFound = NumFound + 1
  42.     END IF
  43.       LOOP WHILE FindNext%
  44.    END IF
  45.  
  46.    PRINT : PRINT NumFound;
  47.    IF DirFlag THEN
  48.      PRINT "directories"
  49.    ELSE
  50.      PRINT "files"
  51.    END IF
  52.  
  53.    PRINT
  54.    PRINT "Find more files? (Y/N): ";
  55.    YN$ = UCASE$(INPUT$(1))
  56.    IF YN$ = "N" THEN END
  57. LOOP
  58.  
  59. FUNCTION FindFirst% (FileSpec$, Attribute%)
  60.  
  61.   DIM FileSpecZ AS STRING * 80
  62.  
  63.   '---- Set up local disk transfer area
  64.   Regs.ax = &H1A00                    'Set DTA function
  65.   Regs.dx = VARPTR(DTA)
  66.   CALL Interrupt(&H21, Regs, Regs)    'call DOS
  67.  
  68.   '---- Call the DOS Find First function
  69.   FileSpecZ$ = FileSpec$ + CHR$(0)    'DOS uses ASCIIZ strings
  70.   Regs.ax = &H4E00                    'DOS Find First function
  71.   Regs.cx = Attribute%                'specify attributes
  72.   Regs.dx = VARPTR(FileSpecZ$)        'DX points to FileSpecZ$
  73.   CALL Interrupt(&H21, Regs, Regs)    'call DOS
  74.  
  75.   FindFirst% = (Regs.flags AND 1) = 0 'True if found
  76.  
  77. END FUNCTION
  78.  
  79. FUNCTION FindNext%
  80.  
  81.   Regs.ax = &H4F00                    'DOS Find Next function
  82.   CALL Interrupt(&H21, Regs, Regs)    'call DOS
  83.   FindNext% = (Regs.flags AND 1) = 0  'True if found
  84.  
  85. END FUNCTION
  86.  
  87. FUNCTION Trim$ (Work$)
  88.  
  89.   Null = INSTR(Work$, CHR$(0))          'find the zero byte
  90.   Trim$ = LEFT$(Work$, Null - 1)        'return all to the left
  91.  
  92. END FUNCTION
  93.  
  94.